#ifndef __LOGGER_H__
#define __LOGGER_H__

#include <fstream>

#ifndef DEBUG
    //#define DEBUG
#endif

class Logger
{
public:
    static Logger& theLogger() { return thisLogger;}
private:
    static Logger thisLogger;
    std::ofstream file;

    Logger()
    {
      #ifdef DEBUG
	open("./debug.log");
      #endif
    };

    ~Logger() 
    {
      close();
    }

    //opens the specified file
    inline void open(const std::string &filename)
    {
        #ifdef DEBUG
            file.open(filename.c_str());
        #endif
    };

    //closes the ofstream
    inline void close()
    {
        #ifdef DEBUG
            file.close();
        #endif
    };
  
    friend inline Logger& operator<<(Logger &logger, std::ostream& (*manipulator)(std::ostream&));
    template <class T> friend inline Logger& operator<<(Logger &logger, const T &t);

};

//output function for endl
inline Logger& operator<<(Logger &logger, std::ostream& (*manipulator)(std::ostream&))
{
    #ifdef DEBUG
        logger.file << manipulator;
    #endif

    return logger;
};

//output function
template <class T>
inline Logger& operator<<(Logger &logger, const T &t)
{
    #ifdef DEBUG
        logger.file << t;
    #endif

    return logger;
};

#endif //LOGGER_H_
